<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: HCZ <huangchengze@etrol.com> 
// +----------------------------------------------------------------------

namespace app\duty\controller\ajax;
//公司关联下拉菜单值

class Panorama {
	
	/**
	 * 获取物资(装备)类型
	 * @param string $id 物资/装备ID
	 */
	public function getMaterialType($id = null){
		$materialType = db('basicinfo')
						->where(array('sysCode'=>22,'parentSubsystemNo'=>$id))
						->field('subsystemName as name,subsystemNo as id')
						->select();
		return json($materialType);
	}
	
	/**
	 * 救援单位专业类型
	 * @param string $id 救援单位类别ID
	 * @return \think\response\Json
	 */
	public function getRescueType($id = null){
		$resuceType = db('basicinfo')
					 ->where('sysCode',15)
					 ->where('parentSubsystemNo',$id)
					 ->field('subsystemName as name,subsystemNo as id')
					 ->select();
		return json($resuceType);
	}
	
	/**
	 * 获取危险源分类
	 * @param string $id 危险源种类ID
	 */
	public function getDangersourceType($id = null){
		$dangersourceType =db('basicinfo')
					 ->where('parentCode',12)
					 ->where('parentSubsystemNo',$id)
					 ->field('subsystemName as name,subsystemNo as id')
					 ->select();
		return json($dangersourceType);
	}
	
	/**
	 * 获取物资装备列表
	 * @param array $data 搜索条件
	 */
	public function getMaterialList(){
		$where = [];
		$data = input('post.');
		if(isset($data['categoryId'])&&$data['categoryId']){
			$where['categoryId'] = $data['categoryId'];
		}
		if(isset($data['typeId'])&&$data['typeId']){
			$where['typeId'] = $data['typeId'];
		}
		if(isset($data['order'])&&$data['order']){
			if($data['order'] != 'distance'){
				$order = $data['order'].' desc';
			}else{
				$order ='id asc';
			}
			
		}
		//分页参数
		if(($limit = input('limit')) && ($page = input('page'))){
			$startLimit =  ($page-1)*$limit;
			//物资装备列表
			$info = collection(model('Basic/Equipe')->with('enterprise,store')->where($where)->order($order)->limit($startLimit.','.$limit)->select())->toArray();
		}else{
			//物资装备列表
			$info = collection(model('Basic/Equipe')->with('enterprise,store')->where($where)->order($order)->select())->toArray();
		}
		//总数
		$count = model('Basic/Equipe')->where($where)->count('id');
	
		if ($count >= 0){
			return json(['code'=>1,'msg'=>'物资信息','count'=>$count,'data'=>$info]);
		}
	}
	
	/**
	 * 获取救援单位列表
	 */
	public function getRescueList(){
		$where = [];
		$data = input('post.');
		if(isset($data['categoryId'])&&$data['categoryId']){
			$where['categoryId'] = $data['categoryId'];
		}
		if(isset($data['typeId'])&&$data['typeId']){
			$where['typeId'] = $data['typeId'];
		}
		if(isset($data['order'])&&$data['order']){
			if($data['order'] == 'id'){
				$order = 'id desc';
			}elseif($data['order'] == 'arriveTime'){
				$order = 'arriveTime asc';
			}else{
				$order ='id asc';
			}
				
		}
		//分页参数
		if(($limit = input('limit')) && ($page = input('page'))){
			$startLimit =  ($page-1)*$limit;
			//物资装备列表
			$info = collection(model('Basic/Rescueunit')->where($where)->order($order)->limit($startLimit.','.$limit)->select())->toArray();
		}else{
			//物资装备列表
			$info = collection(model('Basic/Rescueunit')->where($where)->order($order)->select())->toArray();
		}
		//总数
		$count = model('Basic/Rescueunit')->where($where)->count('id');
		
		if ($count >= 0){
			return json(['code'=>1,'msg'=>'物资信息','count'=>$count,'data'=>$info]);
		}
	}
	
	public function getDangersourceList(){
		$where['sourceType'] =['in',[1,2]];
		$data = input('post.');
		if(isset($data['sourceType'])&&$data['sourceType']){
			$where['sourceType'] = $data['sourceType'];
		}
		if(isset($data['typeId'])&&$data['typeId']){
			$where['typeId'] = $data['typeId'];
		}
		if(isset($data['order'])&&$data['order']){
			if($data['order'] == 'id'){
				$order = 'id desc';
			}elseif($data['order'] == 'status'){
				$order = 'status desc';
			}else{
				$order ='id asc';
			}
				
		}
		//分页参数
		if(($limit = input('limit')) && ($page = input('page'))){
			$startLimit =  ($page-1)*$limit;
			//物资装备列表
			$info = collection(model('Basic/Dangersource')->with('enterprise')->order($order)->where($where)->limit($startLimit.','.$limit)->select())->toArray();
		}else{
			//物资装备列表
			$info = collection(model('Basic/Dangersource')->with('enterprise')->order($order)->where($where)->select())->toArray();
		}
		//总数
		$count = model('Basic/Dangersource')->where($where)->count('id');
		
		if ($count >= 0){
			return json(['code'=>1,'msg'=>'物资信息','count'=>$count,'data'=>$info]);
		}
	}

	/**
	 * 事发危险源
	 * @param string $dangersourceId 企业ID
	 * @return Json
	 */
	public function dangerSources($dangersourceId = null){
		$dangerSource = collection(model('basic/dangersource')->with('sensors')->where('id',$dangersourceId)->select())->toArray();
		return json($dangerSource);
	}






}